package com.hd.hdxgddcommon.utils;


import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/8/14.
 * Description :  集合工具类
 */
public class CollectionUtils {

    public static <T> T getSingle(List<T> list) {
        if (list == null || list.isEmpty()) return null;
        return list.get(0);
    }

    public static boolean isEmpty(Collection list) {
        return list == null || list.isEmpty();
    }

    public static boolean isEmpty(Object[] list) {
        return list == null || list.length == 0;
    }

    public static boolean isNotEmpty(Collection list) {
        return !isEmpty(list);
    }

    public static boolean isNotEmpty(Object[] list) {
        return !isEmpty(list);
    }

    public static boolean isEmpty(Map map) {
        return map == null || map.isEmpty();
    }

    public static boolean isNotEmpty(Map map) {
        return !isEmpty(map);
    }

    public static <T> String join(String separator, Collection<T> collection) {
        return join(separator, "", "", collection);
    }

    public static <T> String join(String separator, String prefix, String suffix, Collection<T> collection) {
        StringBuilder buffer = new StringBuilder();
        boolean first = true;

        if (separator == null) separator = "";
        if (prefix == null) prefix = "";
        if (suffix == null) suffix = "";
        buffer.append(prefix);
        for (Object value : collection) {
            if (first) {
                first = false;
            } else {
                buffer.append(separator);
            }
            buffer.append(value.toString());
        }
        buffer.append(suffix);
        return buffer.toString();
    }

}
